package pl.edu.pw.tm.zestawfiltrow.algorytmy;

import java.awt.image.BufferedImage;

public class BW extends Filter {
	private static String name = "Czarno-biały";

	
	
	@Override
	public BufferedImage run(BufferedImage img) {		
		int rgb;
		int width = img.getWidth();
		int height = img.getHeight();
		BufferedImage newImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
		int[][] px = getPixels(img);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				int sum = getRed(px[i][j]) + getGreen(px[i][j]) + getBlue(px[i][j]);				
				rgb = toRGB(sum/3, sum/3, sum/3);
				newImage.setRGB(i, j, (int) rgb);
			}
		}
		return newImage;
	}

	public String getName() {
		return name;
	}
}